//===============================================================================
// Q4Tech Engineering Team
// Mobile Updater Application Block - November 2006
//===============================================================================
// Copyright  Q4Tech Informatica Argentina.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using Microsoft.ApplicationBlocks.Mobile.Updater;
using Microsoft.ApplicationBlocks.Mobile.Updater.Configuration;
using Microsoft.ApplicationBlocks.Mobile.Updater.Utilities;
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using Q4Tech.Engineering.UpdaterAgent.Configuration;

namespace Q4Tech.Engineering.UpdaterAgent
{
    public class DownloaderFactory : IDownloaderFactory
    {
        public IDownloader CreateDownloader(string downloaderName)
        {
            foreach (DownloaderElement downloaderConfig in UpdaterConfigurationSection.GetSection().Downloaders)
            {
                if (downloaderConfig.Name == downloaderName)
                {
                    Type type = downloaderConfig.Type;
                    return Activator.CreateInstance(type) as IDownloader;
                }
            }

            throw new InvalidOperationException();
        }

        public IDownloader CreateDownloader()
        {
            return CreateDownloader(UpdaterConfigurationSection.GetSection().DefaultDownloader);
        }
    }
}

